import Vue from 'vue';
import VueRouter from 'vue-router';
const routes = [
  {
    path: '/films',
    component: () => import('../views/Films/index.vue'),
    children: [
      {
        path: 'in_theaters',
        component: () => import('../views/Films/Children/InTheaters.vue'),
      },
      {
        path: 'coming_soon',
        component: () => import('../views/Films/Children/ComingSoon.vue'),
      },
    ],
  },
  {
    path: '/city',
    component: () => import('../views/Films/City.vue'),
  },
  {
    path: '/detail',
    component: () => import('../views/Films/Detail.vue'),
  },
  {
    path: '/',
    redirect: '/films/in_theaters',
  },
  {
    path: '*',
    component: () => import('../views/ErrorPage/Error.vue'),
  },
];

const router = new VueRouter({
  routes,
  //使用此方法在电影详情页返回列表页时悬停在该电影前，但是此时路由出口需要用keep-alive包裹，且生命周期函数只有activated和deactivated
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { y: 0 };
    }
  },
});
Vue.use(VueRouter);
export default router;
